package com.yn.front.driver;


import com.yn.common.enums.EnumZyOrderStatus;
import com.yn.common.page.BasePage;
import com.yn.common.request.driver.CarOrderFinishedRequest;
import com.yn.common.request.sc.PageParamRequest;
import com.yn.common.response.driver.ZyDriverCenterListResponse;
import com.yn.common.response.driver.ZyDriverContactResponse;
import com.yn.common.response.driver.ZyDriverOrderDetailResponse;
import com.yn.common.response.driver.ZyDriverOrderListResponse;
import com.yn.common.utils.genutils.CommonResult;
import com.yn.service.service.ZyOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 转运订单
 */
@Slf4j
@RestController()
@RequestMapping("api/driver/order")
@Api(tags = "司机端订单接口")
public class DriverOrderController {

    @Autowired
    private ZyOrderService zyOrderService;


    /**
     * 司机端查询订单列表
     *
    * */
    @ApiOperation(value = "查询转运订单列表")
    @GetMapping(value = "/getZyOrderList")
    public CommonResult<BasePage<ZyDriverOrderListResponse>> getZyOrderList(@NotNull @RequestParam(required = true) Integer transportType, PageParamRequest pageRequest) {
        log.info("查询司机端转运订单列表转运类型：{}", transportType);
        BasePage<ZyDriverOrderListResponse> basePage = zyOrderService.getZyOrderList(transportType,pageRequest);

        return CommonResult.success(basePage);
    }


   /* @ApiOperation(value = "查询转运订单详情")
    @GetMapping(value = "/getZyOrderDetail")
    public CommonResult<ZyOrderQuoteResponse> getZyOrderDetail(String orderNo) {
        log.info("查询转运订单详情入参：{}", orderNo);
        ZyOrderQuoteResponse zyOrderQuoteResponse = zyOrderService.getZyOrderDetail(orderNo);
        return CommonResult.success(zyOrderQuoteResponse);
    }*/

    /**
     * 司机接单前查看订单详情
     * */
    @ApiOperation(value = "查询转运订单详情")
    @GetMapping(value = "/getZyOrderDetail")
    public CommonResult<ZyDriverOrderDetailResponse> getZyOrderDetail(String orderNo) {
        log.info("查询转运订单详情入参：{}", orderNo);
        ZyDriverOrderDetailResponse zyOrderQuoteResponse = zyOrderService.getZyDriverOrderDetail(orderNo);
        return CommonResult.success(zyOrderQuoteResponse);
    }

    /**
     * 司机接单
     * */
    @ApiOperation(value = "司机接单")
    @PostMapping(value = "/takeOrder/{orderNo}")
    public CommonResult<String> takeOrder(@PathVariable String orderNo) {
        log.info("司机接单入参：{}", orderNo);
        zyOrderService.takeOrder(orderNo);
        return CommonResult.success();
    }


    //司机取消订单
    @ApiOperation(value = "司机取消订单")
    @PutMapping(value = "/cancelOrder")
    public CommonResult<String> cancelOrder(@RequestParam(required = true) String orderNo) {
        log.info("取消订单入参：{}", orderNo);
        zyOrderService.driverCancelOrder(orderNo);
        return CommonResult.success();
    }

    /**
     * 司机接单后查看发单人姓名电话
     * */
    @ApiOperation(value = "接单司机查看详情")
    @GetMapping(value = "/contact")
    public CommonResult<ZyDriverContactResponse> lookNamePhone(@RequestParam(required = true) String orderNo) {
        log.info("查看联系方式订单入参：{}", orderNo);
        ZyDriverContactResponse zyDriverContactResponse =zyOrderService.getOrderCenterDetail(orderNo);
        return CommonResult.success(zyDriverContactResponse);
    }

    /**
     * 司机完成订单——将订单状态设置为已送达
     * */
   /* @ApiOperation(value = "司机已送达——完成订单")
    @PostMapping(value = "/finished")
    public CommonResult<String> OrderFinished(@RequestBody CarOrderFinishedRequest request,@RequestParam(value = "orderStatus") Integer orderStatus) {
        log.info("司机已送达入参：request:{},orderStatus:{}", request,orderStatus);
       zyOrderService.OrderFinished(request,orderStatus);
        return CommonResult.success();
    }*/

    /**
     * 司机完成订单——将订单状态设置为已送达
     * */
    @ApiOperation(value = "司机已送达——完成订单")
    @PostMapping(value = "/finished")
    public CommonResult<String> OrderFinished(@RequestParam(value = "orderNo",required = true) String orderNo) {
        log.info("司机已送达入参：request:{}", orderNo);
        zyOrderService.OrderFinished(orderNo, EnumZyOrderStatus.YSD.getCode());
        return CommonResult.success();
    }

    /**
     * 订单中心——司机查询已结单列表
     * */
    @ApiOperation(value = "查询订单中心接单列表")
    @GetMapping(value = "/Center/ZyOrderList")
    public CommonResult<BasePage<ZyDriverCenterListResponse>> zyOrderCenterList( @RequestParam(required = true,defaultValue = "0") Integer isAsc, PageParamRequest pageRequest) {
        log.info("查询司机端订单中心入参,isAsc：{}", isAsc);
        BasePage<ZyDriverCenterListResponse> basePage = zyOrderService.zyOrderCenterList(isAsc,pageRequest);
        return CommonResult.success(basePage);
    }

}



